import sys
import requests
import pip

from utils.weatherJWT_util import getJWT

API_HOST = "ne5hv5j9wq.re.qweatherapi.com"

def getLocation(location : str) -> (str, str):
    url = f"https://{API_HOST}/geo/v2/city/lookup?location={location}"
    headers = {
        "Authorization": f"Bearer {getJWT()}",
        "Accept-Encoding": "gzip, deflate, br"  # 支持压缩
    }

    response = requests.get(url, params=None, headers=headers, timeout=30)

    # 检查请求是否成功
    if response.status_code == 200:
        # 响应会自动解压缩
        data = response.json()  # 如果返回的是JSON
        # print(data)
        return data["location"][0]["name"], data["location"][0]["id"]
    else:
        print(f"Location请求失败，状态码: {response.status_code}, error: {response.text}")
        return "", ""

if __name__ == '__main__':
    result = getLocation("播州区")
    print(result)